home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / QuickDraw / CopyMask / Source / CopyMask.c
Encoding:
C/C++ Source or Header  |  1996-09-17  |  2.6 KB  |  97 lines  |  [TEXT/CWIE]

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                            */
  3. /*        CopyMask.                                                            */
  4. /*            by John Wang                                                    */
  5. /*                                                                            */
  6. /*        Description:    Shows how CopyMask can used to fade a screen to a    */
  7. /*            lighter color.                                                    */
  8. /*                                                                            */
  9. /*        Version:        1.0 Completed 12/2/91                                */
  10. /*                                                                            */
  11. /*--------------------------------------------------------------------------*/
  12.  
  13. #include     <Dialogs.h>
  14. #include    <Fonts.h>
  15. #include     <Processes.h>
  16. #include    <QDOffscreen.h>
  17.  
  18. void main(void)
  19. {
  20.     WindowPtr        mainWinPtr;
  21.     OSErr            error;
  22.     SysEnvRec        theWorld;
  23.     GWorldPtr        myOffscreen1, myOffscreen2;
  24.     GDHandle        oldDevice;
  25.     CGrafPtr        oldPort;
  26.     Rect            windRect, offRect, myRect;
  27.     RGBColor        theColor;
  28.     int                i;
  29.     
  30.     /* Make sure ColorQD exists. */
  31.     error = SysEnvirons(1, &theWorld);
  32.     if (theWorld.hasColorQD == false) {
  33.         SysBeep(50);
  34.         ExitToShell();
  35.     }
  36.     
  37.     /* Initialize all the needed managers. */
  38.     InitGraf(&qd.thePort);
  39.     InitFonts();
  40.     InitWindows();
  41.     InitMenus();
  42.     TEInit();
  43.     InitDialogs(nil);
  44.     InitCursor();
  45.  
  46.     /* Define output window. */
  47.     SetRect(&windRect, 100, 100, 400, 400);
  48.     SetRect(&offRect, 0, 0, 300, 300);
  49.     mainWinPtr = NewCWindow(nil, &windRect, "\pJohn", true, documentProc, (WindowPtr) -1, false, 0);
  50.     SetPort(mainWinPtr);
  51.     GetGWorld(&oldPort, &oldDevice);
  52.  
  53.     /* Create two offscreen GWorlds. */
  54.     if (NewGWorld(&myOffscreen1, 0, &offRect, nil, nil, 0))
  55.         Debugger();
  56.     if (NewGWorld(&myOffscreen2, 0, &offRect, nil, nil, 0))
  57.         Debugger();
  58.     
  59.     /* Now, draw ramp to first offscreen pixmap. */
  60.     SetGWorld(myOffscreen1, nil);
  61.     for (i=0; i<10; i++) {
  62.         theColor.red = theColor.green = theColor.blue = (i*28) << 8;
  63.         RGBForeColor(&theColor);
  64.         SetRect(&myRect, 0, i*30, 300, i*30+30);
  65.         PaintRect(&myRect);
  66.     }
  67.  
  68.     /* Now, draw mask to second offscreen pixmap. */
  69.     SetGWorld(myOffscreen2, nil);
  70.     SetRect(&myRect, 0, 0, 300, 300);
  71.     theColor.red = theColor.green = theColor.blue = (128) << 8;
  72.     RGBForeColor(&theColor);
  73.     PaintRect(&myRect);
  74.  
  75.     /*    Draw to the ramp to the window.    */
  76.     SetGWorld(oldPort, oldDevice);
  77.     CopyBits((BitMapPtr) *myOffscreen1->portPixMap, &(*mainWinPtr).portBits, &offRect,
  78.                 &offRect, 0, nil);
  79.  
  80.     /* Wait until user clicks button. */
  81.     do {
  82.     } while (!Button());
  83.     
  84.     /*    Now fade the window to white using CopyMask.  The destination must be erased
  85.         for CopyMask to work.    */
  86.     SetGWorld(oldPort, oldDevice);
  87.     EraseRect(&offRect);
  88.     CopyMask((BitMapPtr) *myOffscreen1->portPixMap, (BitMapPtr) *myOffscreen2->portPixMap,
  89.                 &(*mainWinPtr).portBits, &offRect, &offRect, &offRect);
  90.  
  91.     /* Wait until user clicks button. */
  92.     do {
  93.     } while (Button());
  94.     do {
  95.     } while (!Button());
  96. }
  97.